package com.sz.rexiang.Activity;

import java.io.FileNotFoundException;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import com.sz.rexiang.R;

import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.internal.widget.AdapterViewCompat.OnItemClickListener;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.VideoView;

@ContentView(R.layout.activity_background)

public class ActivityLevelCheck extends BaseActivity {

	@ViewInject(R.id.level_check_video)
	private VideoView mVideoView;
	@ViewInject(R.id.level_check_video_tv)
	private TextView tvAdd;

	private static final int GET_PIC_FROM_GALLERY = 5;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setTitle(R.string.level_check_center, true);

	}

	@Event(value = { R.id.level_check_btn_ok }, type = View.OnClickListener.class)
	private void onClick(View view) {
		// 必须为private
		switch (view.getId()) {
		case R.id.level_check_btn_ok:
			Intent intent = new Intent();
			intent.setType("video/*");
			intent.setAction(Intent.ACTION_GET_CONTENT);
			startActivityForResult(intent, GET_PIC_FROM_GALLERY);
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == GET_PIC_FROM_GALLERY) {

			showVideoPlay(resultCode, data);

		}

	}

	private void showVideoPlay(int resultCode, Intent data) {
		// TODO Auto-generated method stub
		if (resultCode == RESULT_OK) {
			Uri uri = data.getData();
	
			Cursor cursor = getContentResolver().query(uri, null, null, null, null);
			cursor.moveToFirst();
			int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
			String videoPath = cursor.getString(column_index); // 图片文件路径
			tvAdd.setVisibility(View.GONE);
			mVideoView.setVisibility(View.VISIBLE);
			cursor.close();
			
			Log.d("msg", "--->path:"+videoPath);
			mVideoView.setVideoPath(videoPath);
			mVideoView.start();

		}
	}

}
